package com.gec.hawaste.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.gec.hawaste.entity.Examine;
import com.gec.hawaste.mapper.ExamineMapper;
import com.gec.hawaste.service.IExamineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gec.hawaste.vo.ExamineVo;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lisongsong
 * @since 2022-04-21
 */
@Service
public class ExamineServiceImpl extends ServiceImpl<ExamineMapper, Examine> implements IExamineService {

    @Override
    public IPage<ExamineVo> selectExamineVoByCondition(IPage<ExamineVo> page, Map<String, Object> params) {

        QueryWrapper<ExamineVo> queryWrapper = new QueryWrapper<>();
        // 动态拼接sql


        // 拼接上 固定的那一段条件
        queryWrapper.apply("examine.del_flag= 0 " +
                "and examine.examine_user_id = sys_user.id " +
                "and sys_user.office_id = sys_office.id ")
                // eq(boolean condition, R column, Object val);
                .eq(params.containsKey("type")&& !ObjectUtils.isEmpty(params.get("type")),"examine.type",params.get("type"))
                .eq(params.containsKey("officeId")&&!ObjectUtils.isEmpty(params.get("officeId")),"sys_office.id",params.get("officeId"))
                .like(params.containsKey("name")&&!ObjectUtils.isEmpty("name"),"sys_user.name",params.get("name"));

        /**
         *
         *   examine.del_flag= 0
         and examine.examine_user_id = sys_user.id
         and sys_user.office_id = sys_office.id

         // 下面这三个条件  用户有可能不传入， 所以需要判断  条件是否存在
         and examine.type=1
         and sys_office.id = 56
         and sys_user.name like '%人员%'
         *
         */


        //   public IPage<ExamineVo> selectExamineVoByCondition(IPage<ExamineVo> page, @Param("ew") Wrapper ew);
        // 调用 ExamineMapper 的方法
        return   this.baseMapper.selectExamineVoByCondition(page,queryWrapper);
    }
    // 扩展service
}
